from sys import exit
from bitcoin.core.script import *

from utils import *
from config import my_private_key, my_public_key, my_address, faucet_address
from ex1 import send_from_P2PKH_transaction


######################################################################
# TODO: Complete the scriptPubKey implementation for Exercise 3
ex3a_txout_scriptPubKey = [OP_2DUP, OP_ADD, 2211, OP_EQUALVERIFY, OP_SUB, 447 ,OP_EQUAL]   #脚本公钥
#OP_2DUP复制栈顶两个元素，并将它们再次压入栈中
#OP_ADD计算提供的x+y，OP_EQUALVERIFY验证是否等于2211，OP_SUB计算提供的x-y,OP_EQUAL验证是否等于447
######################################################################

if __name__ == '__main__':
    ######################################################################
    # TODO: set these parameters correctly
    amount_to_send = 0.000001 
    txid_to_spend = (
        '4e506e7540ec8931641112b53b74e4fa1f51aa1d00d41e12bba5dd0afcc047ca')
    utxo_index =3
    ######################################################################

    response = send_from_P2PKH_transaction(
        amount_to_send, txid_to_spend, utxo_index,
        ex3a_txout_scriptPubKey)
    print(response.status_code, response.reason)
    print(response.text)
